<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class CourtAnnounce extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->library('HttpPost');
		$this->load->model('Court_Model');
		$this->load->helper('url_helper');
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 *        http://example.com/index.php/welcome
	 *    - or -
	 *        http://example.com/index.php/welcome/index
	 *    - or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */

	//获取开庭公告列表
	public function courtlist()
	{
		$data['pageno'] = '';
		$data['pagesize'] = 15;
		$data['cbfy'] = '全部';
		$data['yg'] = '';
		$data['bg'] = '';
		$data['spz'] = '';
		$search_key = '';
		if (isset($_POST['search_key']) && ($_POST['search_key'] != '')) {
			$search_key = $_POST['search_key'];
		}
		if (isset($_POST['pageno']) && ($_POST['pageno'] != '')) {
			$data['pageno'] = $_POST['pageno'];
		} else {
			$data['pageno'] = 1;
		}
		if (isset($_POST['pagesize'])) {
			$data['pagesize'] = $_POST['pagesize'];
		} else {
			$data['pagesize'] = 15;
		}
		if (isset($_POST['cbfy']) && ($_POST['cbfy'] != '')) {
			$data['cbfy'] = $_POST['cbfy'];
		} else {
//			$data['cbfy'] = '全部';
			$data['cbfy'] = '1304';
		}

		if (isset($_POST['yg']) && ($_POST['yg'] != '')) {
			$data['yg'] = $_POST['yg'];
		}
		if (isset($_POST['bg']) && ($_POST['bg'] != '')) {
			$data['bg'] = $_POST['bg'];
		}
		if (isset($_POST['jarq1']) && ($_POST['jarq1'] != '')) {
			$data['jarq1'] = $_POST['jarq1'];
		}
		if (isset($_POST['jarq2']) && ($_POST['jarq2'] != '')) {
			$data['jarq2'] = $_POST['jarq2'];
		}
		if (isset($_POST['spz']) && ($_POST['spz'] != '')) {
			$data['spz'] = $_POST['spz'];
		}
		$url = 'http://www.zjsfgkw.cn/Notice/NoticeKTSearch';
		$timeout = 40;
		$response = $this->httppost->post($url, $data, $timeout);
		$courts=array();
		if (!($this->input->post("isAjax"))) {
			$courts=$this->Court_Model-> get_all_courts();
		}
		$courtlist = json_decode($response);
		$searchsel = array();
		$searchsel['search_key'] = $search_key;
		$searchsel['yg'] = $data['yg'];
		$searchsel['bg'] = $data['bg'];
		$searchsel['spz'] = $data['spz'];
		$searchsel['cbfy'] = $data['cbfy'];
		$articles = array('title' => '开庭公告');
		$articles['court_announces'] = $courtlist;
		$articles['searchsel'] = $searchsel;
		$articles['courts'] = $courts;
		if ($this->input->post("isAjax")) {
			header('content-type:application:json;charset=utf8');
			header('Access-Control-Allow-Origin:*');
			header('Access-Control-Allow-Methods:POST');
			header('Access-Control-Allow-Headers:x-requested-with,content-type');
			$result = array();
			$result['isSuccess'] = true;
			$result['errorMessage'] = '';
			$result['data'] = $courtlist;
			echo json_encode($result, JSON_UNESCAPED_UNICODE);
		} else {
			$this->load->view('head_sec', $articles);
			$this->load->view('court_announce_list', $articles);
			$this->load->view('foot_sec', $articles);
		}
	}

	public function http_test(){
		$url = 'https://api.weixin.qq.com/datacube/getupstreammsg?access_token=Z7lONmLDXnG_EtGDOU0QXrsy8CWTEXXTJjM3585vxYu8HRfMRYrPKfEimV9traN_CwNFPnCo9HX6uJi_QRCJgVEuE2i3AiZOODMybh3E7H0NwlzzFzRo2IY2d8vnEf_3DHSdADANRC';
		$data=array();
		$data['begin_date']='2016-05-02';
		$data['end_date']='2016-05-05';
		$dt1=json_encode($data);
		$timeout = 40;
		$response = $this->httppost->post($url, $dt1, $timeout);
		print_r($response);
		$articles['title']='fddfdf';
		$this->load->view('head_sec', $articles);
		$this->load->view('about', $articles);
		$this->load->view('foot_sec', $articles);
	}
	public function detail($id){
		$article=$this->Article_Model->get_article_by_id($id);
		$title=$article['title'];
		$content=$article['content'];
		$data=array('title'=>$title,
			'content'=>$content
		);
		$this->load->view('head_sec',$data);
		$this->load->view('article_detail',$data);
		$this->load->view('foot_sec',$data);
	}
}


